function shuffle(arr, n) {
  const length = Math.min(arr.length, n)
  const last = length - 1
  for (let i = 0; i < length; ++i) {
    const randomIndex = Math.floor(Math.random() * (last - i + 1)) + i
    let temp = [arr[randomIndex]]
    arr[randomIndex] = arr[i]
    arr[i] = temp
  }
  return arr.slice(0, length)
}

export default shuffle
